package com.note.service;

import com.note.mapper.CommMapper;
import com.note.pojo.Comm;
import com.note.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Service
public class CommServiceImpl implements CommService {
    @Autowired
    private CommMapper commMapper;

    @Override
    public List<Comm> getComsByNoteId(Integer id) {
        return commMapper.getComsByNoteId(id);
    }

    @Override
    public void inserComm(Comm comm, HttpSession session) {
        comm.setCreatetime(new Date());
        User user = (User) session.getAttribute("user");
        if (user==null){
            comm.setUserid(null); //匿名
        }else {
            comm.setUserid(user.getId());
        }
        commMapper.inserComm(comm);
    }

    @Override
    public void zan(Comm comm) {
        commMapper.zan(comm);
    }

    @Override
    public Comm getComById(Integer id) {
        return commMapper.getComById(id);
    }

    @Override
    public List getlikeById(Integer id) {
        return commMapper.getlikeById(id);
    }

    @Override
    public void delComById(Integer id) {
        commMapper.delComById(id);
    }
}
